package com.polaris.live.widget.tab

import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.RectF
import android.graphics.Typeface
import android.util.AttributeSet
import android.util.TypedValue
import android.view.View
import android.view.ViewTreeObserver
import android.widget.HorizontalScrollView
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.viewpager2.widget.ViewPager2
import com.blankj.utilcode.util.ColorUtils
import com.blankj.utilcode.util.SizeUtils
import com.polaris.live.R
import com.polaris.live.common.ext.autoDp
import com.vanniktech.ui.children
import java.util.LinkedList
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

/**
 * TabSizeView
 *
 * @author Created by lucas on 2023/10/16 13:59
 */
class TabSizeView(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet), ITab {

    private var mIndicatorMode = 0 //模式
    private var mIndicatorTextColor = 0 //指示器默认文字颜色
    private var mIndicatorSelectTextColor = 0 //指示器选择文字颜色
    private var mIndicatorTextSize = 0 //指示器默认文字大小
    private var mIndicatorSelectTextSize = 0 //指示器选择文字大小
    private var mIndicatorPadding = 0 //指示器边距
    private var mIndicatorTextStyle = 0 //指示器默认文字style
    private var mIndicatorSelectTextStyle = 0 //指示器选择文字style
    private var mIndicatorLineType = 0 //下划线类型
    private var mIndicatorLineModel = 0 //下划线模式
    private var mIndicatorLineColor = 0 //下划线颜色
    private var mIndicatorLineWidth = 0 //下划线长度
    private var mIndicatorLineHeight = 0 //下划线宽度
    private var mIndicatorLinePadding = 0 //下划线间距
    private var mIndicatorLineRoundRadius = 0f //下划线圆角
    private var mIndicatorRightShow = true//是否显示右侧图片
    private var mIndicatorRightImage = 0//右侧图片

    private val mList = ArrayList<ITabEntity>()
    private val mTextWidths = ArrayList<Float>()
    private val mRecyclerViews = LinkedList<View>()
    private val mHelper = NavigatorHelper()

    private val mRectDot = RectF()
    private val mRect = RectF()

    private var mPager: ViewPager2? = null
    private var mOnTabSelectListener: OnTabSelectListener? = null
    private var mOnPageSelectedListener: OnPageSelectedListener? = null

    private val mLinePaint: Paint
    private var mLineEnter = 0f
    private var mLineLeave = 0f
    private var mLinePercent = 0f

    private var mEnterWidth = 0f
    private var mLeaveWidth = 0f

    private var mEnterIndex = 0
    private var mLeaveIndex = 0

    private var mOnGlobalLayoutListener: ViewTreeObserver.OnGlobalLayoutListener? = null
    private var mOnScrollGlobalLayoutListener: ViewTreeObserver.OnGlobalLayoutListener? = null
    private var mScrollView: HorizontalScrollView? = null

    private var mParentWidth: Int = 0   //当前控件宽
    private var mDesiredWidth: Int = 200.autoDp  //默认

    private var mIsScrollView = false
    private var mScrollWidth = 0

    init {
        initAttrs(attributeSet)
        mLinePaint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.DITHER_FLAG)
        mLinePaint.color = mIndicatorLineColor
        initView()
    }

    private fun initAttrs(attrs: AttributeSet?) {
        if (attrs == null) {
            return
        }
        val typedArray = context.obtainStyledAttributes(attrs, R.styleable.TabSizeView)
        mIndicatorMode = typedArray.getInt(R.styleable.TabSizeView_indicatorMode, MODE_NONE)
        mIndicatorTextColor = typedArray.getColor(
            R.styleable.TabSizeView_indicatorTextColor,
            ColorUtils.getColor(R.color.a7a8ad)
        )
        mIndicatorSelectTextColor = typedArray.getColor(
            R.styleable.TabSizeView_indicatorSelectTextColor,
            ColorUtils.getColor(R.color.a7a8ad)
        )
        mIndicatorTextSize = typedArray.getDimension(
            R.styleable.TabSizeView_indicatorTextSize,
            DEFAULT_TEXT_SIZE.toFloat()
        ).toInt()
        mIndicatorSelectTextSize = typedArray.getDimension(
            R.styleable.TabSizeView_indicatorSelectTextSize,
            DEFAULT_SELECT_TEXT_SIZE.toFloat()
        ).toInt()
        mIndicatorPadding = typedArray.getDimension(
            R.styleable.TabSizeView_indicatorPadding,
            DEFAULT_PADDING.toFloat()
        ).toInt()
        mIndicatorTextStyle = typedArray.getInt(R.styleable.TabSizeView_indicatorTextStyle, 0)
        mIndicatorSelectTextStyle = typedArray.getInt(R.styleable.TabSizeView_indicatorSelectTextStyle, 0)
        mIndicatorLineType = typedArray.getInt(R.styleable.TabSizeView_indicatorLineType, LINE_NONE)
        mIndicatorLineModel = typedArray.getInt(R.styleable.TabSizeView_indicatorLineMode, LINE_MODEL_NONE)
        mIndicatorLineColor = typedArray.getColor(
            R.styleable.TabSizeView_indicatorLineColor,
            ColorUtils.getColor(R.color.a7a8ad)
        )
        mIndicatorLineWidth = typedArray.getDimension(
            R.styleable.TabSizeView_indicatorLineWidth,
            SizeUtils.dp2px(15f).toFloat()
        ).toInt()
        mIndicatorLineHeight = typedArray.getDimension(
            R.styleable.TabSizeView_indicatorLineHeight,
            SizeUtils.dp2px(3f).toFloat()
        ).toInt()
        mIndicatorLinePadding = typedArray.getDimension(
            R.styleable.TabSizeView_indicatorLinePadding,
            SizeUtils.dp2px(7f).toFloat()
        ).toInt()
        mIndicatorLineRoundRadius = typedArray.getDimension(
            R.styleable.TabSizeView_indicatorLineRoundRadius, SizeUtils.dp2px(3f).toFloat()
        )
        mIndicatorRightShow = typedArray.getBoolean(R.styleable.TabSizeView_indicatorRightShow, true)
        mIndicatorRightImage = typedArray.getResourceId(R.styleable.TabSizeView_indicatorRightImage, 0)
        typedArray.recycle()
    }

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec)

        val widthMode = MeasureSpec.getMode(widthMeasureSpec)
        val widthSize = MeasureSpec.getSize(widthMeasureSpec)
        val heightSize = MeasureSpec.getSize(heightMeasureSpec)
        mParentWidth = if (mIsScrollView) {
            mScrollWidth
        } else {
            when (widthMode) {
                MeasureSpec.UNSPECIFIED -> max(widthSize, mDesiredWidth)
                MeasureSpec.AT_MOST -> min(widthSize, mDesiredWidth)
                MeasureSpec.EXACTLY -> widthSize
                else -> mDesiredWidth
            }
        }
        setMeasuredDimension(mParentWidth, heightSize)
    }

    private fun initView() {
        if (mIndicatorLineType == LINE_UNDERLINE || mIndicatorLineType == LINE_UNDERLINE_NOT_DOT) {
            setPadding(paddingStart, paddingTop, paddingEnd, paddingBottom + mIndicatorLinePadding)
        }

        mHelper.setNavigatorScrollListener(object : NavigatorHelper.OnNavigatorScrollListener {
            override fun onEnter(
                index: Int,
                totalCount: Int,
                enterPercent: Float,
                leftToRight: Boolean,
            ) {
                mEnterIndex = index
                render(mLeaveIndex, index, 1 - enterPercent, enterPercent)
            }

            override fun onLeave(
                index: Int,
                totalCount: Int,
                leavePercent: Float,
                leftToRight: Boolean,
            ) {
                mLeaveIndex = index
            }

            override fun onSelected(index: Int, totalCount: Int) {
                val holder = getHolder(index)
                holder.mTvTitle.setTextColor(mIndicatorSelectTextColor)
                if (mIndicatorSelectTextStyle == 1) {
                    holder.mTvTitle.typeface = Typeface.defaultFromStyle(Typeface.BOLD)
                } else if (mIndicatorSelectTextStyle == 0) {
                    holder.mTvTitle.typeface = Typeface.defaultFromStyle(Typeface.NORMAL)
                }
                if (mIndicatorRightShow) {
                    if (mIndicatorRightImage != 0) {
                        holder.mIvSelector.setImageResource(mIndicatorRightImage)
                    }
                    holder.mIvSelector.visibility = View.VISIBLE
                }

                if (index == 0) {
                    mScrollView?.fullScroll(
                        if (isRightLayout()) {
                            FOCUS_RIGHT
                        } else {
                            FOCUS_LEFT
                        }
                    )
                } else if (index == totalCount - 1) {
                    mScrollView?.fullScroll(
                        if (isRightLayout()) {
                            FOCUS_LEFT
                        } else {
                            FOCUS_RIGHT
                        }
                    )
                } else {
                    if (mScrollView != null) {
                        val sx = mScrollView?.scrollX ?: 0
                        val sw = mScrollView?.width ?: 0
                        val x = if (isRightLayout()) {
                            mParentWidth - abs(mLineEnter.toInt()) - mEnterWidth.toInt() - mIndicatorPadding
                        } else {
                            mLineEnter.toInt()
                        }

                        if (x > sw + sx || x < sx) {
                            mScrollView?.smoothScrollTo(x, 0)
                        }

                    }
                }

                mOnPageSelectedListener?.onSelected(index)
            }

            override fun onDeselected(index: Int, totalCount: Int) {
                val holder = getHolder(index)
                holder.mTvTitle.setTextColor(mIndicatorTextColor)
                if (mIndicatorSelectTextStyle == 0) {
                    holder.mTvTitle.typeface = Typeface.defaultFromStyle(Typeface.NORMAL)
                } else if (mIndicatorSelectTextStyle == 1) {
                    holder.mTvTitle.typeface = Typeface.defaultFromStyle(Typeface.BOLD)
                }

                if (mIndicatorRightShow) {
                    holder.mIvSelector.visibility = View.GONE
                }

                mOnPageSelectedListener?.onDeselected(index)
            }
        })
    }

    private val mPageChangeListener = object : ViewPager2.OnPageChangeCallback() {
        override fun onPageScrolled(
            position: Int,
            positionOffset: Float,
            positionOffsetPixels: Int,
        ) {
            mHelper.onPageScrolled(position, positionOffset, positionOffsetPixels)
        }

        override fun onPageSelected(position: Int) {
            mHelper.onPageSelected(position)
        }

        override fun onPageScrollStateChanged(state: Int) {
            mHelper.onPageScrollStateChanged(state)
        }
    }

    override fun setViewPage(pager: ViewPager2) {
        mPager?.unregisterOnPageChangeCallback(mPageChangeListener)
        mPager = pager
        pager.registerOnPageChangeCallback(mPageChangeListener)
    }

    fun getViewPager(): ViewPager2? {
        return mPager
    }

    fun onPageSelected(position: Int) {
        mHelper.onPageSelected(position)
    }

    private var mIsClearAfter = false
    private var mDefPosition = 0

    fun <T : ITabEntity> resetTabs(tabs: List<T>, defPosition: Int) {
        mIsClearAfter = true
        mDefPosition = defPosition
        setTabs(tabs)
    }

    fun addTab(tab: ITabEntity) {
        mList.add(tab)

        mHelper.setTotalCount(mList.size)

        mDefPosition = mHelper.getCurrentIndex()
        updateIndicator(mIsClearAfter, true)
    }

    override fun setTabs(tabs: List<ITabEntity>) {
        mList.clear()
        mList.addAll(tabs)

        mTextWidths.clear()

        mHelper.setTotalCount(mList.size)

        updateIndicator(mIsClearAfter)
    }

    /**
     *
     */
    fun setRed(position: Int, show: Boolean) {
        if (position >= 0 && position < mList.size) {
            val holder = getHolder(position)
            holder.mTabRed.visibility = if (show) VISIBLE else GONE
        }
    }

    /**
     * 设置带滑动的tabs
     */
    fun setTabs(tabs: List<ITabEntity>, scrollView: HorizontalScrollView) {
        setTabs(tabs)
        mIsScrollView = true
        if (mOnGlobalLayoutListener == null) {
            mOnGlobalLayoutListener = ViewTreeObserver.OnGlobalLayoutListener {
                val lastView = children().lastOrNull()
                val w = lastView?.width
                if (w != null && w > 0) {
                    viewTreeObserver.removeOnGlobalLayoutListener(mOnGlobalLayoutListener)
                    mOnGlobalLayoutListener = null

                    val width = abs(lastView.translationX.toInt()) +
                            lastView.width + paddingStart + paddingEnd + mIndicatorPadding / 2

                    val lp = layoutParams
                    lp.width = width
                    layoutParams = lp
                    mScrollWidth = width
                    //阿拉伯会弹一下，给scroll回来
                    if (isRightLayout()) {
                        mScrollView?.viewTreeObserver?.removeOnGlobalLayoutListener(mOnScrollGlobalLayoutListener)
                        mOnScrollGlobalLayoutListener = ViewTreeObserver.OnGlobalLayoutListener {
                            mScrollView?.viewTreeObserver?.removeOnGlobalLayoutListener(mOnScrollGlobalLayoutListener)
                            mOnScrollGlobalLayoutListener = null

                            mScrollView?.scrollTo(width * 2, 0)
                        }
                        mScrollView?.viewTreeObserver?.addOnGlobalLayoutListener(mOnScrollGlobalLayoutListener)
                    }
                }
            }
            viewTreeObserver.addOnGlobalLayoutListener(mOnGlobalLayoutListener)
        }
        mScrollView = scrollView
    }

    /**
     * 获取当前下标文本内容
     */
    fun getTabContent(position: Int): String? {
        return mList.getOrNull(position)?.tabTitle
    }

    fun updateIndicator(
        isClearAfter: Boolean = false, isAdd: Boolean = false,
    ) {
        val count = mList.size
        var childCount = childCount

        if (isClearAfter) {
            removeAllViews()
            mRecyclerViews.clear()
            childCount = 0
        }
        if (count > childCount) {
            for (i in childCount until count) {
                addView(i)
            }
        } else {
            for (i in childCount - 1 downTo count) {
                removeView(i)
            }
        }
        if (count == 0) {
            return
        }
        for (i in 0 until count) {
            val entity = mList[i]
            val child = getChildAt(i)
            val holder = ViewHolder(child)

            holder.mTvTitle.text = entity.tabTitle
            holder.mTvTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, mIndicatorTextSize.toFloat())
            holder.mTvTitle.setTextColor(mIndicatorTextColor)
            //如果有粗体要先设置上，不然计算会有问题   导致一些长的文字会换行
            if (mIndicatorSelectTextStyle == 1) {
                holder.mTvTitle.typeface = Typeface.defaultFromStyle(Typeface.BOLD)
            } else if (mIndicatorSelectTextStyle == 0) {
                holder.mTvTitle.typeface = Typeface.defaultFromStyle(Typeface.NORMAL)
            }
        }
        if (isAdd) {
            render2(
                0,
                mHelper.getCurrentIndex(),
                0f,
                1f
            )
        } else {
            render2(
                -1,
                if (mIsClearAfter && mHelper.getCurrentIndex() == mDefPosition) mDefPosition else 0,
                0f,
                1f
            )
        }

    }

    private fun render2(
        leavePosition: Int,
        enterPosition: Int,
        leavePercent: Float,
        enterPercent: Float,
    ) {
        getHolder(enterPosition).mTvTitle.setTextColor(mIndicatorSelectTextColor)
        render(leavePosition, enterPosition, leavePercent, enterPercent)
    }

    private fun render(
        leavePosition: Int,
        enterPosition: Int,
        leavePercent: Float,
        enterPercent: Float,
    ) {
        var left = 0f
        val scale = mIndicatorSelectTextSize / mIndicatorTextSize.toFloat()
        val poor = (mIndicatorSelectTextSize - mIndicatorTextSize).toFloat()
        val leaveScale = 1 + (scale - 1) * leavePercent
        val leavePoor = poor * leavePercent
        val enterScale = 1 + (scale - 1) * enterPercent
        val enterPoor = poor * enterPercent
        var padding = mIndicatorPadding.toFloat()
        var textWidth = 0f
        val count = mList.size
        if (mIndicatorMode == MODE_ADJUST || mIndicatorMode == MODE_CENTER) {
            for (i in 0 until count) {
                val sizeWidth = getSizeWidth(i)
                textWidth += if (i == enterPosition) {
                    sizeWidth * enterScale
                } else if (i == leavePosition) {
                    sizeWidth * leaveScale
                } else {
                    sizeWidth
                }
            }
            if (mIndicatorMode == MODE_CENTER) {
                left = (mParentWidth - (textWidth + padding * (count - 1f))) / 2
            }
            if (mIndicatorMode == MODE_ADJUST || left < 0) {
                padding = (mParentWidth - textWidth) / (count - 1f)
                left = 0f
            }
        }
        for (i in 0 until count) {
            val holder = getHolder(i)
            val view = holder.itemView
            val sizeWidth = getSizeWidth(i)
            val spaceWidth = sizeWidth + padding

            if (i == enterPosition) {
                mLineEnter = left
                if (enterPosition <= leavePosition) {
                    mLinePercent = enterPercent
                }
                mEnterWidth = sizeWidth
                left = renderSelect(left, enterScale, enterPoor, view, sizeWidth)
            } else if (i == leavePosition) {
                mLineLeave = left
                if (enterPosition > leavePosition) {
                    mLinePercent = leavePercent
                }
                mLeaveWidth = sizeWidth
                left = renderSelect(left, leaveScale, leavePoor, view, sizeWidth)
            } else {
                view.scaleX = 1f
                view.scaleY = 1f
                view.translationX = if (isRightLayout()) {
                    -left
                } else {
                    left
                }
                view.translationY = 0f
            }

            left += spaceWidth
        }
        if (mLinePercent == 0f) {
            mLinePercent = 1f
        }
        invalidate()
        //遇到在滑动控件中没有走ViewTreeObserver.OnGlobalLayoutListener的问题，计算完后强制布局
        requestLayout()
    }

    private fun renderSelect(
        left: Float,
        scale: Float,
        poor: Float,
        view: View,
        sizeWidth: Float,
    ): Float {
        view.scaleX = scale
        view.scaleY = scale

        val width = (sizeWidth * scale - sizeWidth) / 2

        var tmpLeft = left + width
        //rtl适配
        view.translationX = if (isRightLayout()) {
            -tmpLeft
        } else {
            tmpLeft
        }
        //居中不需要设置translationY
//        view.translationY = -poor / 2

        tmpLeft += width

        return tmpLeft
    }

    private fun getSizeWidth(position: Int): Float {
        if (position < mTextWidths.size) {
            return mTextWidths[position]
        }
        val entity = mList[position]
        val holder = getHolder(position)
        val textView = holder.mTvTitle

        val paint = textView.paint
        val originalTypeface = paint.typeface
        val isBold = (originalTypeface?.style ?: 0) and Typeface.BOLD != 0

        // 如果当前字体不是粗体，设置为粗体
        if (!isBold) {
            paint.typeface = Typeface.create(originalTypeface, Typeface.BOLD)
        }
        // 计算粗体文本的宽度
        val sizeWidth = paint.measureText(entity.tabTitle)
        // 留出10%的空间
        val adjustedWidth = sizeWidth * 1.05f  // 增加5%
        // 恢复原来的字体样式
        if (!isBold) {
            paint.typeface = originalTypeface
        }
        mTextWidths.add(adjustedWidth)
        return adjustedWidth
    }

    override fun dispatchDraw(canvas: Canvas) {
        super.dispatchDraw(canvas)
        if (mIndicatorLineType == LINE_NONE || childCount == 0) {
            return
        }
        var percent = (1f - mLinePercent) * 2f
        if (percent > 1f) {
            percent = 1f
        }

        val lineLeft = min(mLineEnter, mLineLeave)
        val lineRight = max(mLineEnter, mLineLeave)

        val offset = LEFT_PADDING +
                (if (mLinePercent == 1f) mLineEnter else lineLeft) +
                (lineRight - lineLeft) * (1f - mLinePercent)

        mRectDot.left = offset
        mRectDot.right = mRectDot.left + mIndicatorLineRoundRadius + mIndicatorLineRoundRadius * percent * 1.5f
        mRectDot.bottom = height.toFloat()
        mRectDot.top = mRectDot.bottom - mIndicatorLineRoundRadius
        if (mIndicatorLineType == LINE_UNDERLINE_NOT_DOT) {
            if (mIndicatorLineModel == LINE_MODEL_NONE) {
                mRect.left = offset + mIndicatorSelectTextSize - SizeUtils.dp2px(11f)
            } else {
                val scale = mIndicatorSelectTextSize / mIndicatorTextSize.toFloat()

                val directionRight = mEnterIndex > mLeaveIndex
                val currentWidth = if (mLinePercent == 1f) {
                    mEnterWidth
                } else {
                    if (directionRight) {
                        mEnterWidth * (1 - mLinePercent) + mLeaveWidth * mLinePercent
                    } else {
                        mEnterWidth * mLinePercent + mLeaveWidth * (1 - mLinePercent)
                    }
                } * scale

                mRect.left = if (isRightLayout()) {
                    mParentWidth - offset - LEFT_PADDING - (currentWidth / 2 + (mIndicatorLineWidth * scale / 2))
                } else {
                    offset - LEFT_PADDING + (currentWidth / 2 - (mIndicatorLineWidth * scale / 2))
                }
            }
        } else {
            mRect.left = offset + mIndicatorLineRoundRadius * 2
        }

        mRect.right = mRect.left + mIndicatorLineWidth
        mRect.bottom = mRectDot.bottom
        mRect.top = mRect.bottom - mIndicatorLineHeight

        if (mIndicatorLineType != LINE_UNDERLINE_NOT_DOT) {
            canvas.drawRoundRect(
                mRectDot,
                mIndicatorLineRoundRadius,
                mIndicatorLineRoundRadius,
                mLinePaint
            )
        }
        canvas.drawRoundRect(mRect, mIndicatorLineRoundRadius, mIndicatorLineRoundRadius, mLinePaint)
    }

    private fun addView(index: Int) {
        val tmpView = if (mRecyclerViews.isNotEmpty()) {
            mRecyclerViews.poll()?.also {
                it.setOnClickListener(null)
            }
        } else {
            null
        }
        val view = tmpView ?: inflate(context, createView(), null)

        val lp = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)
        lp.addRule(CENTER_VERTICAL)
        addView(view, lp)

        view.setOnClickListener {
            val pager = mPager
            val l = mOnTabSelectListener
            if (l != null) {
                if (!l.interceptClick(index)) {
                    if (pager != null && pager.currentItem == index) {
                        l.onTabReselect(index)
                    } else {
                        l.onTabSelect(index)
                    }
                }
            } else {
                if (pager != null) {
                    pager.currentItem = index
                }
            }
        }
    }

    private fun isRightLayout() = context.resources.configuration.layoutDirection == LAYOUT_DIRECTION_RTL

    private fun createView(): Int {
        return R.layout.widget_item_tab_size
    }

    private fun removeView(position: Int) {
        val view = getChildAt(position) ?: return
        mRecyclerViews.add(view)
        removeViewAt(position)
    }

    private fun getHolder(position: Int): ViewHolder {
        return getChildAt(position).tag as ViewHolder
    }

    override fun setOnTabSelectListener(l: OnTabSelectListener) {
        mOnTabSelectListener = l
    }

    fun setOnPageSelectedListener(l: OnPageSelectedListener) {
        mOnPageSelectedListener = l
    }

    class ViewHolder(val itemView: View) {

        val mTvTitle: TextView = itemView.findViewById(R.id.text)
        val mIvSelector: ImageView = itemView.findViewById(R.id.selector)
        val mTabRed: View = itemView.findViewById(R.id.tab_red)

        init {
            itemView.tag = this
        }
    }

    fun setIndicatorMode(indicatorMode: Int) {
        mIndicatorMode = indicatorMode
    }

    fun setIndicatorTextColor(indicatorTextColor: Int) {
        mIndicatorTextColor = indicatorTextColor
    }

    fun setIndicatorSelectTextColor(indicatorSelectTextColor: Int) {
        mIndicatorSelectTextColor = indicatorSelectTextColor
    }

    fun setIndicatorTextSize(indicatorTextSize: Int) {
        mIndicatorTextSize = indicatorTextSize
    }

    fun setIndicatorSelectTextSize(indicatorSelectTextSize: Int) {
        mIndicatorSelectTextSize = indicatorSelectTextSize
    }

    fun setIndicatorPadding(indicatorPadding: Int) {
        mIndicatorPadding = indicatorPadding
    }

    fun setIndicatorTextStyle(indicatorTextStyle: Int) {
        mIndicatorTextStyle = indicatorTextStyle
    }

    fun setIndicatorSelectTextStyle(indicatorSelectTextStyle: Int) {
        mIndicatorSelectTextStyle = indicatorSelectTextStyle
    }

    fun setIndicatorLineType(indicatorLineType: Int) {
        mIndicatorLineType = indicatorLineType
    }

    fun setIndicatorLineColor(indicatorLineColor: Int) {
        mIndicatorLineColor = indicatorLineColor
    }

    fun setIndicatorLineWidth(indicatorLineWidth: Int) {
        mIndicatorLineWidth = indicatorLineWidth
    }

    fun setIndicatorLineHeight(indicatorLineHeight: Int) {
        mIndicatorLineHeight = indicatorLineHeight
    }

    fun setIndicatorLinePadding(indicatorLinePadding: Int) {
        mIndicatorLinePadding = indicatorLinePadding
    }

    fun setIndicatorLineRoundRadius(indicatorLineRoundRadius: Float) {
        mIndicatorLineRoundRadius = indicatorLineRoundRadius
    }

    companion object {

        private val DEFAULT_TEXT_SIZE = SizeUtils.sp2px(18f)
        private val DEFAULT_SELECT_TEXT_SIZE = SizeUtils.sp2px(24f)
        private val DEFAULT_PADDING = SizeUtils.dp2px(16f)
        private val LEFT_PADDING = SizeUtils.dp2px(2.5f)

        const val LINE_NONE = 0
        const val LINE_UNDERLINE = 1
        const val LINE_UNDERLINE_NOT_DOT = 2
        const val LINE_MODEL_NONE = 0
        const val LINE_MODEL_CENTER = 1
        const val MODE_NONE = 0
        const val MODE_ADJUST = 1
        const val MODE_CENTER = 2
    }
}